package io.noties.markwon.base.image.span

import io.noties.markwon.base.MarkwonConfiguration
import io.noties.markwon.base.RenderProps
import io.noties.markwon.base.SpanFactory
import io.noties.markwon.base.image.AsyncRecycleDrawable
import io.noties.markwon.base.image.load.AsyncRecycleDrawableLoader
import io.noties.markwon.base.image.ImageProps
import timber.log.Timber


class RecycleImageSpanFactory : SpanFactory {
    override fun getSpans(configuration: MarkwonConfiguration, props: RenderProps): Any {
        Timber.d("RecycleImageSpanFactory get AsyncRecycleDrawableSpan")
        return AsyncRecycleDrawableSpan(
            configuration.theme,
            AsyncRecycleDrawable(
                ImageProps.DESTINATION.require(props),
                configuration.asyncDrawableLoader() as AsyncRecycleDrawableLoader,
                configuration.imageSizeResolver(),
                ImageProps.IMAGE_SIZE[props]
            ),
            AsyncDrawableSpan.ALIGN_BOTTOM,
            ImageProps.REPLACEMENT_TEXT_IS_LINK[props, false]
        )
    }
}